
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/27/2010 23:21:18
-- Generated from EDMX file: C:\privat\skole\diplom\SIS_Wcf_Server\SIS_Wcf_Server\Model\SISModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SISDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_net_gps_relations_gpsPositioner]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[net_gps_relations] DROP CONSTRAINT [FK_net_gps_relations_gpsPositioner];
GO
IF OBJECT_ID(N'[dbo].[FK_net_gps_relations_net]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[net_gps_relations] DROP CONSTRAINT [FK_net_gps_relations_net];
GO
IF OBJECT_ID(N'[dbo].[FK_net_net_relations_net]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[net_net_relations] DROP CONSTRAINT [FK_net_net_relations_net];
GO
IF OBJECT_ID(N'[dbo].[FK_net_net_relations_net1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[net_net_relations] DROP CONSTRAINT [FK_net_net_relations_net1];
GO
IF OBJECT_ID(N'[dbo].[FK_InformationsData_Information]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[InformationsData] DROP CONSTRAINT [FK_InformationsData_Information];
GO
IF OBJECT_ID(N'[dbo].[FK_InformationsData_Tags_relations_InformationsData]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[InformationsData_Tags_relations] DROP CONSTRAINT [FK_InformationsData_Tags_relations_InformationsData];
GO
IF OBJECT_ID(N'[dbo].[FK_InformationsData_Tags_relations_Tags]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[InformationsData_Tags_relations] DROP CONSTRAINT [FK_InformationsData_Tags_relations_Tags];
GO
IF OBJECT_ID(N'[dbo].[FK_information_gpsPosition_relations_gpsPositioner]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[information_gpsPosition_relations] DROP CONSTRAINT [FK_information_gpsPosition_relations_gpsPositioner];
GO
IF OBJECT_ID(N'[dbo].[FK_information_gpsPosition_relations_Information]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[information_gpsPosition_relations] DROP CONSTRAINT [FK_information_gpsPosition_relations_Information];
GO
IF OBJECT_ID(N'[dbo].[FK_information_net_relations_Information]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[information_net_relations] DROP CONSTRAINT [FK_information_net_relations_Information];
GO
IF OBJECT_ID(N'[dbo].[FK_information_net_relations_net]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[information_net_relations] DROP CONSTRAINT [FK_information_net_relations_net];
GO
IF OBJECT_ID(N'[dbo].[FK_geocoded_nets_net]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[geocoded_nets] DROP CONSTRAINT [FK_geocoded_nets_net];
GO
IF OBJECT_ID(N'[dbo].[FK_none_geocoded_netsnet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[net] DROP CONSTRAINT [FK_none_geocoded_netsnet];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[gpsPositioner]', 'U') IS NOT NULL
    DROP TABLE [dbo].[gpsPositioner];
GO
IF OBJECT_ID(N'[dbo].[net]', 'U') IS NOT NULL
    DROP TABLE [dbo].[net];
GO
IF OBJECT_ID(N'[dbo].[Information]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Information];
GO
IF OBJECT_ID(N'[dbo].[InformationsData]', 'U') IS NOT NULL
    DROP TABLE [dbo].[InformationsData];
GO
IF OBJECT_ID(N'[dbo].[Tags]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tags];
GO
IF OBJECT_ID(N'[dbo].[geocoded_nets]', 'U') IS NOT NULL
    DROP TABLE [dbo].[geocoded_nets];
GO
IF OBJECT_ID(N'[dbo].[none_geocoded_netsSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[none_geocoded_netsSet];
GO
IF OBJECT_ID(N'[dbo].[net_gps_relations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[net_gps_relations];
GO
IF OBJECT_ID(N'[dbo].[net_net_relations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[net_net_relations];
GO
IF OBJECT_ID(N'[dbo].[InformationsData_Tags_relations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[InformationsData_Tags_relations];
GO
IF OBJECT_ID(N'[dbo].[information_gpsPosition_relations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[information_gpsPosition_relations];
GO
IF OBJECT_ID(N'[dbo].[information_net_relations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[information_net_relations];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'gpsPositioner'
CREATE TABLE [dbo].[gpsPositioner] (
    [ID] uniqueidentifier  NOT NULL,
    [Lat] float  NULL,
    [Long] float  NULL,
    [DateTimeCreated] datetime  NULL
);
GO

-- Creating table 'net'
CREATE TABLE [dbo].[net] (
    [Id] uniqueidentifier  NOT NULL,
    [Type] nvarchar(50)  NULL,
    [Value] nvarchar(50)  NULL,
    [DateTimeCreated] datetime  NULL,
    [none_geocoded_netsnet_net_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'Information'
CREATE TABLE [dbo].[Information] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Titel] nvarchar(100)  NULL,
    [ValidUntil] datetime  NULL
);
GO

-- Creating table 'InformationsData'
CREATE TABLE [dbo].[InformationsData] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Beskrivelse] nvarchar(max)  NULL,
    [Type] nvarchar(20)  NULL,
    [Data] nvarchar(max)  NULL,
    [InformationId] int  NULL
);
GO

-- Creating table 'Tags'
CREATE TABLE [dbo].[Tags] (
    [Id] uniqueidentifier  NOT NULL,
    [Tag] nvarchar(50)  NULL
);
GO

-- Creating table 'geocoded_nets'
CREATE TABLE [dbo].[geocoded_nets] (
    [Id] uniqueidentifier  NOT NULL,
    [NetId] uniqueidentifier  NULL,
    [Lat] float  NULL,
    [Long] float  NULL,
    [Dist] float  NULL
);
GO

-- Creating table 'none_geocoded_netsSet'
CREATE TABLE [dbo].[none_geocoded_netsSet] (
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'net_gps_relations'
CREATE TABLE [dbo].[net_gps_relations] (
    [gpsPositioner_ID] uniqueidentifier  NOT NULL,
    [net_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'net_net_relations'
CREATE TABLE [dbo].[net_net_relations] (
    [net2_Id] uniqueidentifier  NOT NULL,
    [net1_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'InformationsData_Tags_relations'
CREATE TABLE [dbo].[InformationsData_Tags_relations] (
    [InformationsData_Id] int  NOT NULL,
    [Tags_Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'information_gpsPosition_relations'
CREATE TABLE [dbo].[information_gpsPosition_relations] (
    [gpsPositioner_ID] uniqueidentifier  NOT NULL,
    [Information_Id] int  NOT NULL
);
GO

-- Creating table 'information_net_relations'
CREATE TABLE [dbo].[information_net_relations] (
    [Information_Id] int  NOT NULL,
    [net_Id] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'gpsPositioner'
ALTER TABLE [dbo].[gpsPositioner]
ADD CONSTRAINT [PK_gpsPositioner]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'net'
ALTER TABLE [dbo].[net]
ADD CONSTRAINT [PK_net]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Information'
ALTER TABLE [dbo].[Information]
ADD CONSTRAINT [PK_Information]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'InformationsData'
ALTER TABLE [dbo].[InformationsData]
ADD CONSTRAINT [PK_InformationsData]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Tags'
ALTER TABLE [dbo].[Tags]
ADD CONSTRAINT [PK_Tags]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'geocoded_nets'
ALTER TABLE [dbo].[geocoded_nets]
ADD CONSTRAINT [PK_geocoded_nets]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'none_geocoded_netsSet'
ALTER TABLE [dbo].[none_geocoded_netsSet]
ADD CONSTRAINT [PK_none_geocoded_netsSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [gpsPositioner_ID], [net_Id] in table 'net_gps_relations'
ALTER TABLE [dbo].[net_gps_relations]
ADD CONSTRAINT [PK_net_gps_relations]
    PRIMARY KEY NONCLUSTERED ([gpsPositioner_ID], [net_Id] ASC);
GO

-- Creating primary key on [net2_Id], [net1_Id] in table 'net_net_relations'
ALTER TABLE [dbo].[net_net_relations]
ADD CONSTRAINT [PK_net_net_relations]
    PRIMARY KEY NONCLUSTERED ([net2_Id], [net1_Id] ASC);
GO

-- Creating primary key on [InformationsData_Id], [Tags_Id] in table 'InformationsData_Tags_relations'
ALTER TABLE [dbo].[InformationsData_Tags_relations]
ADD CONSTRAINT [PK_InformationsData_Tags_relations]
    PRIMARY KEY NONCLUSTERED ([InformationsData_Id], [Tags_Id] ASC);
GO

-- Creating primary key on [gpsPositioner_ID], [Information_Id] in table 'information_gpsPosition_relations'
ALTER TABLE [dbo].[information_gpsPosition_relations]
ADD CONSTRAINT [PK_information_gpsPosition_relations]
    PRIMARY KEY NONCLUSTERED ([gpsPositioner_ID], [Information_Id] ASC);
GO

-- Creating primary key on [Information_Id], [net_Id] in table 'information_net_relations'
ALTER TABLE [dbo].[information_net_relations]
ADD CONSTRAINT [PK_information_net_relations]
    PRIMARY KEY NONCLUSTERED ([Information_Id], [net_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [gpsPositioner_ID] in table 'net_gps_relations'
ALTER TABLE [dbo].[net_gps_relations]
ADD CONSTRAINT [FK_net_gps_relations_gpsPositioner]
    FOREIGN KEY ([gpsPositioner_ID])
    REFERENCES [dbo].[gpsPositioner]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [net_Id] in table 'net_gps_relations'
ALTER TABLE [dbo].[net_gps_relations]
ADD CONSTRAINT [FK_net_gps_relations_net]
    FOREIGN KEY ([net_Id])
    REFERENCES [dbo].[net]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_net_gps_relations_net'
CREATE INDEX [IX_FK_net_gps_relations_net]
ON [dbo].[net_gps_relations]
    ([net_Id]);
GO

-- Creating foreign key on [net2_Id] in table 'net_net_relations'
ALTER TABLE [dbo].[net_net_relations]
ADD CONSTRAINT [FK_net_net_relations_net]
    FOREIGN KEY ([net2_Id])
    REFERENCES [dbo].[net]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [net1_Id] in table 'net_net_relations'
ALTER TABLE [dbo].[net_net_relations]
ADD CONSTRAINT [FK_net_net_relations_net1]
    FOREIGN KEY ([net1_Id])
    REFERENCES [dbo].[net]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_net_net_relations_net1'
CREATE INDEX [IX_FK_net_net_relations_net1]
ON [dbo].[net_net_relations]
    ([net1_Id]);
GO

-- Creating foreign key on [InformationId] in table 'InformationsData'
ALTER TABLE [dbo].[InformationsData]
ADD CONSTRAINT [FK_InformationsData_Information]
    FOREIGN KEY ([InformationId])
    REFERENCES [dbo].[Information]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_InformationsData_Information'
CREATE INDEX [IX_FK_InformationsData_Information]
ON [dbo].[InformationsData]
    ([InformationId]);
GO

-- Creating foreign key on [InformationsData_Id] in table 'InformationsData_Tags_relations'
ALTER TABLE [dbo].[InformationsData_Tags_relations]
ADD CONSTRAINT [FK_InformationsData_Tags_relations_InformationsData]
    FOREIGN KEY ([InformationsData_Id])
    REFERENCES [dbo].[InformationsData]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Tags_Id] in table 'InformationsData_Tags_relations'
ALTER TABLE [dbo].[InformationsData_Tags_relations]
ADD CONSTRAINT [FK_InformationsData_Tags_relations_Tags]
    FOREIGN KEY ([Tags_Id])
    REFERENCES [dbo].[Tags]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_InformationsData_Tags_relations_Tags'
CREATE INDEX [IX_FK_InformationsData_Tags_relations_Tags]
ON [dbo].[InformationsData_Tags_relations]
    ([Tags_Id]);
GO

-- Creating foreign key on [gpsPositioner_ID] in table 'information_gpsPosition_relations'
ALTER TABLE [dbo].[information_gpsPosition_relations]
ADD CONSTRAINT [FK_information_gpsPosition_relations_gpsPositioner]
    FOREIGN KEY ([gpsPositioner_ID])
    REFERENCES [dbo].[gpsPositioner]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Information_Id] in table 'information_gpsPosition_relations'
ALTER TABLE [dbo].[information_gpsPosition_relations]
ADD CONSTRAINT [FK_information_gpsPosition_relations_Information]
    FOREIGN KEY ([Information_Id])
    REFERENCES [dbo].[Information]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_information_gpsPosition_relations_Information'
CREATE INDEX [IX_FK_information_gpsPosition_relations_Information]
ON [dbo].[information_gpsPosition_relations]
    ([Information_Id]);
GO

-- Creating foreign key on [Information_Id] in table 'information_net_relations'
ALTER TABLE [dbo].[information_net_relations]
ADD CONSTRAINT [FK_information_net_relations_Information]
    FOREIGN KEY ([Information_Id])
    REFERENCES [dbo].[Information]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [net_Id] in table 'information_net_relations'
ALTER TABLE [dbo].[information_net_relations]
ADD CONSTRAINT [FK_information_net_relations_net]
    FOREIGN KEY ([net_Id])
    REFERENCES [dbo].[net]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_information_net_relations_net'
CREATE INDEX [IX_FK_information_net_relations_net]
ON [dbo].[information_net_relations]
    ([net_Id]);
GO

-- Creating foreign key on [NetId] in table 'geocoded_nets'
ALTER TABLE [dbo].[geocoded_nets]
ADD CONSTRAINT [FK_geocoded_nets_net]
    FOREIGN KEY ([NetId])
    REFERENCES [dbo].[net]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_geocoded_nets_net'
CREATE INDEX [IX_FK_geocoded_nets_net]
ON [dbo].[geocoded_nets]
    ([NetId]);
GO

-- Creating foreign key on [none_geocoded_netsnet_net_Id] in table 'net'
ALTER TABLE [dbo].[net]
ADD CONSTRAINT [FK_none_geocoded_netsnet]
    FOREIGN KEY ([none_geocoded_netsnet_net_Id])
    REFERENCES [dbo].[none_geocoded_netsSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_none_geocoded_netsnet'
CREATE INDEX [IX_FK_none_geocoded_netsnet]
ON [dbo].[net]
    ([none_geocoded_netsnet_net_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------